﻿<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<?php
if (!(isset($_GET["id"]))) {
header("Location: browse.php");
exit();
}
?>
<?php
include("siteName.php");
$sOut = "<p>Welcome to the " . $siteName . " site";
if (isset($_SESSION["uName"])) {
$sOut .= ", " . $_SESSION["uName"];
}
$sOut .= "<br />Below is the information relating to the '%s'.</p>";
$vName = "";
$vDescription = "";
$vPrice = "";
$vURLs = "";
$imagesArray = array();
$disabled = "";
$quantityValue = "1";
$productID = "0";
require("dbInc.php");
$mysqliObj = new mysqli($dbHost, $dbUser, $dbPass, $dbDB);
$productID = mysqli_real_escape_string($mysqliObj, $_GET["id"]);
$sql = sprintf("select vName, vDescription, fPrice, vURLs from %s where id = %s;", $tableProducts, $productID);
$res = $mysqliObj->query($sql);
if ($res->num_rows > 0) {
$row = $res->fetch_assoc();
$sOut = sprintf($sOut, $row["vName"]);
$vName = $row["vName"];
$vDescription = str_replace("\n", "<br />\n", str_replace("\'", "&#039;", $row["vDescription"]));
$vPrice = $currencySymbol . sprintf("%1\$.2f", floatval($row["fPrice"]));
$vURLs = $row["vURLs"];
$sql = sprintf("select id, vPath, vDescription from %s where iProductID = %s;", $tableImages, $productID);
$res = $mysqliObj->query($sql);
$res->data_seek(0);
if ($res->num_rows > 0) {
while ($row = $res->fetch_assoc()) {
//id, vPath, vDescription
array_push($imagesArray, array("id"=>$row["id"], "vPath"=>$row["vPath"], "vDescription"=>str_replace("\'", "&#039;", $row["vDescription"])));
}//end of looping through image data rows
}//end of checking if images in DB
$mysqliObj->close();
} else {
$mysqliObj->close();
header("Location: cat.php?id=" . $_GET["catid"]);
exit();
}//end of checking for product data row
//check if add form submitted
if (isset($_POST["btnAdd"])) {
if (!(isset($_SESSION["cart"]))) {
$_SESSION["cart"] = array();
}//end of checking if there was a cart session array
$quantityValue = $_POST["txtQuantity"];
if (is_numeric($quantityValue)) {
array_push($_SESSION["cart"], array($productID, $_POST["txtQuantity"]));
$msg = "Product added to cart";
$disabled = " disabled";
} else {
$msg = "You must enter a numeric value";
}//end of making sure quantity is numeric
}//end of checking form submission
?>
<title><?php echo $siteName; ?> - Product information</title>
<link type="text/css" rel="stylesheet" href="styles.css" />
<script type="text/javascript" language="javascript">
function validateForm(theForm) {
with (theForm) {
var qValue = txtQuantity.value;
var retValue = true;
var allowChars = "0123456789.";
if (qValue.length < 1) {
retValue = false;
} else {
for (var I = 0;I<qValue.length; I++) {
if (allowChars.indexOf(qValue.charAt(I)) < 0) {
retValue = false;
}//end of checking each character
}//end of looping
}//end of check if value entered
}//end of with clause
if (retValue != true) {
alert("You must enter a numeric value");
}
return retValue;
}//end of validateForm function

function checkMsg() {
var msg = "<?php echo $msg; ?>";
if (msg.length > 0) {
alert(msg);
}
}//end of checkMsg function
</script>
</head>
<body onload="checkMsg();">
<iframe name="logoFrame" id="logoFrame" src="logo.htm" border="0" height="120" align="top" frameborder="0" marginheight="0" width="100%" scrolling="no">
<a href="http://www.blindza.co.za/" target="_blank">
<img src="logo/blindza_logo_smaller46.jpg" alt="blindZA.co.za logo - white text on black background, with white border - and red braille version hovering in front of normal text" width="317" height="103" border="0" />
</a>
</iframe>
<a onclick="window.close();">Close</a>
<h2><?php echo $siteName; ?> - Product information</h2>
<p><?php echo $sOut; ?></p>
<table align="center" border="0">
<tr>
<th align="right">Product name:</th>
<td><?php echo $vName; ?></td>
</tr>
<tr>
<th align="right" valign="top">Product description:</th>
<td><?php echo $vDescription; ?></td>
</tr>
<tr>
<th align="right">Product price:</th>
<td><?php echo $vPrice; ?></td>
</tr>
<?php
if (strlen($vURLs) > 2) {
$urlArray = explode("\n", $vURLs);
?>
<tr>
<th align="right" valign="top">Reference URL&#039;s:</th>
<td>
<ul>
<?php
foreach ($urlArray as $url) {
if (strlen(trim($url)) > 0) {
echo sprintf("<li><a href='%s' target=_blank'>%s</a></li>\n", $url, $url);
}
}//end of looping through URLs
?>
</ul>
</td>
</tr>
<?php
}//end of checking if there are URLs to display
if (count($imagesArray) > 0) {
?>
<tr>
<td colspan="2">
<?php
//id, vPath, vDescription
foreach ($imagesArray as $img) {
$imgFile = "./images/" . $img["id"];
$imgFile .= substr($img["vPath"], strripos($img["vPath"], "."));
echo sprintf("<a href='%s' target='_blank'><img src='%s' width='100' alt='%s' /></a>\n", $imgFile, $imgFile, $img["vDescription"]);
}//end of looping through images
?>
</td>
</tr>
<?php
}//end of checking if there are images to display
?>
</table>
<a onclick="window.close();">Close</a>
<h3>Purchase product</h3>
<form action="product.php?catid=<?php echo $_GET['catid'] . '&id=' . $_GET['id']; ?>" method="post" enctype="multipart/form-data" onsubmit="return validateForm(this);">
<table align="center" border="0">
<tr>
<th align="right">Enter quantity (integer/round numeric value)</th>
<td>
<input type="text" name="txtQuantity" id="txtQuantity" value="<?php echo $quantityValue; ?>" />
</td>
</tr>
<tr>
<th align="center" colspan="2">
<input type="submit" name="btnAdd" value="Add to basket"<?php echo $disabled; ?> />
</th>
</tr>
</table>
</form>
<a onclick="window.close();">Close</a>
</body>
</html>
